/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package conexao;

//import ConexaoBanco.DAOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author Administrador
 */
public class ConectaBanco {

     public static Connection getConnection() throws DAOException{
       try{
           Class.forName("com.mysql.jdbc.Driver");
           //return DriverManager.getConnection("jdbc:mysql://10.0.0.5/loja_virtual", "root","");
           return DriverManager.getConnection("jdbc:mysql://localhost/ubiquo", "root","");
       }catch(Exception e){
           System.out.println(e.getMessage());
           throw new DAOException(e.getMessage());
       }
     }

  public static void closeConnection(Connection conn, Statement stmt, ResultSet rs) throws DAOException{
       close(conn, stmt, rs);
   }

   public static void closeConnection(Connection conn, Statement stmt) throws DAOException{
       close(conn, stmt, null);
   }

   public static void closeConnection(Connection conn) throws DAOException{
       close(conn, null, null);
   }

   public static void close(Connection conn, Statement stmt, ResultSet rs) throws DAOException{
       try{
           if (rs != null) rs.close();
           if (stmt != null) stmt.close();
           if (conn != null) conn.close();
       }catch(Exception e){
           throw new DAOException(e.getMessage());
       }
   }

}
